home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
-
- //
- // Source file for "Highlight" node.
- //
-
- #include <Inventor/SoDB.h>
- #include <Inventor/SoDetail.h>
- #include <Inventor/events/SoMouseButtonEvent.h>
- #include <Inventor/events/SoLocation2Event.h>
- #include <Inventor/actions/SoActions.h>
- #include "Highlight.h"
-
- // Define necessary static type id and field variables
- SO_SUBNODE_ID_VARS(Highlight);
- SO_SUBNODE_FIELD_VARS(Highlight);
-
- // Define required type id, name inquiry, and field methods
- SO_SUBNODE_ID_METHODS(Highlight);
- SO_SUBNODE_FIELD_METHODS(Highlight);
-
- //
- // This initializes the Highlight class.
- //
- void
- Highlight::initClass()
- {
- SO_SUBNODE_INIT_ID(Highlight, "Highlight", SoSeparator);
- }
-
- //
- // Constructor
- //
- Highlight::Highlight()
- {
- // One-time initialization code:
- SO_SUBNODE_BEGIN_PROTOTYPE(Highlight);
-
- /* If this node had fields, they would be initialized here...
- // Initialize field data and add fields with default values
- SO_SUBNODE_INIT_FIELDS(Highlight);
- SO_SUBNODE_ADD_FIELD(label, ("<Undefined label>"));
- SO_SUBNODE_ADD_FIELD(minValue, (0.0));
- SO_SUBNODE_ADD_FIELD(maxValue, (1.0));
- SO_SUBNODE_ADD_FIELD(value, (0.0));
- SO_SUBNODE_ADD_FIELD(step, (0.0));
- */
-
- SO_SUBNODE_END_PROTOTYPE();
-
- // The rest of this code is performed for every instance
-
- /*
- // Copy default field values set up in initClass() into this
- // instance
- SO_SUBNODE_INIT_FROM_FIELD_DATA();
- */
-
- highlight = FALSE;
- }
-
- //
- // Destructor
- //
- Highlight::~Highlight()
- {
- }
-
- //
- // Traversal
- //
- void
- Highlight::traverse(SoAction *action)
- {
- int nextIndex;
- int code = getTraversalCode(action, nextIndex);
-
- int whichChild = getWhichChild();
-
- if ((whichChild != -1) &&
- ((code != IN_PATH) ||
- (code == IN_PATH && (whichChild <= nextIndex)))) {
- action->pushCurPath(whichChild);
- action->traverse(getChild(whichChild));
- action->popCurPath();
- }
- }
-
- //
- // Returns which child to traverse for the current state of the
- // Highlight, -1 if none.
- //
- int
- Highlight::getWhichChild() const
- {
- int whichChild = -1;
- int numChildren = getNumChildren();
-
- if (numChildren) {
-
- // If only one child, always draw it
- if (numChildren == 1)
- whichChild = 0;
-
- // If two (or more) children, first is normal, second is highlighted
- else if (numChildren == 2)
- whichChild = (int) highlight;
- }
-
- return whichChild;
- }
-
-
- //
- // Misc actions that will only traverse one of the children.
- //
- void
- Highlight::GLRender(SoGLRenderAction *a) { traverse(a); }
- void
- Highlight::rayPick(SoRayPickAction *a) { traverse(a); }
- void
- Highlight::getBoundingBox(SoGetBoundingBoxAction *a) { traverse(a); }
- void
- Highlight::hiddenLine(SoHiddenLineAction *a) { traverse(a); }
- void
- Highlight::painters(SoPaintersAction *a) { traverse(a); }
-
- //
- // Handles events on this Highlight nodes
- //
- void
- Highlight::handleEvent(SoHandleEventAction *action)
- {
- const SoEvent *event = action->getEvent();
- SbBool isPress = SO_MOUSE_PRESS_EVENT(event, BUTTON1);
- SbBool isMotion =
- event->isOfType(SoLocation2Event::getClassTypeId());
-
- SbBool isHit = FALSE;
- SoDetail *detail = NULL;
- if (isPress || isMotion) {
- detail = action->getDetail();
- if (detail) {
- const SoPath *path = detail->getPath();
- isHit = path->containsNode(this);
- }
- }
-
- SbBool newHighlight = highlight;
-
- if (isPress && isHit) {
- // printf("Ouch! Quit it.\n");
- }
- else if (isMotion)
- newHighlight = isHit;
-
- if (highlight != newHighlight) {
- highlight = newHighlight;
- // Calling touch forces notification, which in turn forces a redraw
- touch();
- }
- }
-
-